package com.dingqb.ktdemo.lambda

import com.dingqb.ktdemo.oop.delegatemode.v
import java.lang.Exception

fun main(args: Array<String>) {
    if (args.size > 0) {
        println("----");
    } else {
        println("----");
    }
    var t: (Int, Int) -> Int = { x, y -> x + y }
    var value = t(11, 22);
    println(value)
    lambda_();
    println(addInt(2, 3))
    varargf(1, 1, 2, 2, 3, 4, 5)
    var s: Int? = 10;
    if (s != null) {
        println("==" + s.toInt())
    } else {
        print("null")
    }

    parse();


}

private fun lambda_() {
    var result: (Int, Int) -> Int = { a, b -> a + b };
    println(result(111, 222));
}

fun addInt(a: Int, b: Int) = a + b
fun sum(a: Int, b: Int) = a + b   // public 方法则必须明确写出返回类型

/**
 *  可变参数
 */
fun varargf(vararg v: Int) {
    for (vv in v) {
        System.err.println(vv);
    }
}

fun parse() {
    var vvv = try {
        var s: String = "101";
        Integer.parseInt(s);
    } catch (e: Exception) {
        e.printStackTrace()
    } finally {
        System.err.println("finally");
    }
    System.err.println("end:" + vvv)
    val v=10;
}